package com.raymond.entity.settlement;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.raymond.config.CustomerIntegerEnumDeserializer;
import com.raymond.config.CustomerIntegerEnumSerializer;
import com.raymond.config.exception.BusinessException;
import com.raymond.entity.commons.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * desc-结算单状态枚举
 *
 * @author houmenghe
 * @date 2025/04/21 17:05
 **/
@Getter
@AllArgsConstructor
@JsonDeserialize(using = CustomerIntegerEnumDeserializer.class)
@JsonSerialize(using = CustomerIntegerEnumSerializer.class)
public enum OrderSettlementStatusEnum implements BaseEnum {

    /**
     * 编制中
     */
    DRAFT(10, "编制中"),
    /**
     * 待确认
     */
    WAIT_CONFIRM(20, "待确认"),
    /**
     * 已拒绝
     */
    REJECT(30, "已拒绝"),
    /**
     * 已确认
     */
    CONFIRM(40, "已确认"),
    /**
     * 已结算
     */
    SETTLEMENT(50, "已结算"),

    /**
     * 已作废
     */
    INVALID(-100, "已作废");

    private final Integer value;

    private final String desc;

    /**
     * 根据结算单状态值获取结算单状态
     *
     * @param v 值
     * @return 结算单状态
     */
    public static OrderSettlementStatusEnum getByValue(Integer v) {
        return Arrays.stream(OrderSettlementStatusEnum.values())
                .filter(f -> Objects.equals(f.getValue(), v))
                .findFirst()
                .orElseThrow(() -> new BusinessException(String.format("该「%s」结算单类型不存在", v)));
    }
}
